package com.zj.easytotwitter.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


import com.zj.easytotwitter.fragment.PolicyItemFragment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZJ on 2017/7/31 0031.
 */

public class PolicyTabPageAdapter extends FragmentPagerAdapter {
    /**
     * Tab标题
     */
    private List<String> list=new ArrayList<>();

    public PolicyTabPageAdapter(FragmentManager fm, List<String> list) {
        super(fm);
        this.list = list;
    }

    @Override
    public Fragment getItem(int position) {
        //新建一个Fragment来展示ViewPager item的内容，并传递参数
        Fragment fragment = new PolicyItemFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        bundle.putSerializable("list", (Serializable) list);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return list.get(position%list.size()).toString();
    }

    @Override
    public int getCount() {
        return list.size();
    }
}
